/**
 * 
 */
package mblog.core.pojos;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.faxsun.core.pojos.enums.PostType;

/**
 * @author langhsu
 * @author songdragon
 */
public class Post implements Serializable {
	private static final long serialVersionUID = -1144627551517707139L;

	private long id;
	private PostType type;
	private String title;
	private String summary;
	private String content;
	private String markdown;
	private String tags;
	private Attach snapshot;
	private Date created;
	private Date updated;
	private User author;
	private int featured; // 是否推荐
	private int hearts; // 喜欢
	private int comments;
	private int views; // 阅读
	private int status;

	// 默认类别Tag
	//private Tag defaultCategory;
	private Tag productTag;
	private List<Tag> tagList;
	
	//是否作为首页banner显示
	private int banner;
	//banner 顺序
	private int bannerIndex;

	// extends
	private List<Attach> albums;
    
	//关注数
    private int followsCounts;
    //点赞数
    private int thumbupCounts;
    
    //用户相关变量
    private String isUserFollowed;
    private long followerId;
    private String isUserThumbsup;
    
    //转载自
    private String sourceWebsite;
    private String sourceUrl;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public PostType getEnumType() {
		return type;
	}

	public int getType() {
		return PostType.getIntValue(type);
	}

	public void setEnumType(PostType type) {
		this.type = type;
	}

	public void setType(int type) {
		this.type = PostType.parse(type);
		if (this.type.equals(PostType.INVALID)) {
			this.type = PostType.EVALUATION;
		}
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Attach getSnapshot() {
		return snapshot;
	}

	public void setSnapshot(Attach snapshot) {
		this.snapshot = snapshot;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}

	public User getAuthor() {
		return author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public List<Attach> getAlbums() {
		return albums;
	}

	public void setAlbums(List<Attach> albums) {
		this.albums = albums;
	}

	public int getFeatured() {
		return featured;
	}

	public void setFeatured(int featured) {
		this.featured = featured;
	}

	public int getHearts() {
		return hearts;
	}

	public void setHearts(int hearts) {
		this.hearts = hearts;
	}

	public int getComments() {
		return comments;
	}

	public void setComments(int comments) {
		this.comments = comments;
	}

	public int getViews() {
		return views;
	}

	public void setViews(int views) {
		this.views = views;
	}

	public String getMarkdown() {
		return markdown;
	}

	public void setMarkdown(String markdown) {
		this.markdown = markdown;
	}

	/*public Tag getDefaultCategory() {
		return defaultCategory;
	}

	public void setDefaultCategory(Tag defaultCatgory) {
		this.defaultCategory = defaultCatgory;
	}
	*/
	public Tag getProductTag() {
		return productTag;
	}

	public void setProductTag(Tag productTag) {
		this.productTag = productTag;
	}

	 public List<Tag> getTagList() {
	 return tagList;
	 }
	
	 public void setTagList(List<Tag> tagList) {
	 this.tagList = tagList;
	 }
	 
	 public String getTagJSON(){
		 //FIXME:将json操作封装
		 ObjectMapper mapper=new ObjectMapper();
		 try {
			return  mapper.writeValueAsString(this.tagList);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
			return "[]";
		}
	 }

	// **** 用于表单显示和提交
	public int getBanner() {
		return banner;
	}

	public void setBanner(int banner) {
		this.banner = banner;
	}

	public int getBannerIndex() {
		return bannerIndex;
	}

	public void setBannerIndex(int index) {
		this.bannerIndex = index;
	}

    public int getFollowsCounts() {
        return followsCounts;
    }

    public void setFollowsCounts(int followsCounts) {
        this.followsCounts = followsCounts;
    }

    public String getIsUserFollowed() {
        return isUserFollowed;
    }

    public void setIsUserFollowed(String isUserFollowed) {
        this.isUserFollowed = isUserFollowed;
    }

    public long getFollowerId() {
        return followerId;
    }

    public void setFollowerId(long followerId) {
        this.followerId = followerId;
    }
	
	// ****
    public String getSourceWebsite() {
		return sourceWebsite;
	}

	public void setSourceWebsite(String sourceWebsite) {
		this.sourceWebsite = sourceWebsite;
	}

	public String getSourceUrl() {
		return sourceUrl;
	}

	public void setSourceUrl(String sourceUrl) {
		this.sourceUrl = sourceUrl;
	}

	public void setType(PostType type) {
		this.type = type;
	}

	public int getThumbupCounts() {
		return thumbupCounts;
	}

	public void setThumbupCounts(int thumbupCounts) {
		this.thumbupCounts = thumbupCounts;
	}

	public String getIsUserThumbsup() {
		return isUserThumbsup;
	}

	public void setIsUserThumbsup(String isUserThumbsup) {
		this.isUserThumbsup = isUserThumbsup;
	}

}
